console.log('[编辑器自定义配置开始,加载完monaco库后触发...]', this);

let codeVueIns = this;
let { gitee } = codeVueIns;

customActions();

// 提示配置
suggestion();

function customActions(){
    
}

function suggestion() {

    return new Promise((resolve, reject) => {
        let data = getCompletionConfig();
        for (let oneLanguage in data) {
            monaco.languages.registerCompletionItemProvider(oneLanguage, {
                provideCompletionItems: function (model, position) {
                    var word = model.getWordUntilPosition(position);
                    var range = {
                        startLineNumber: position.lineNumber,
                        endLineNumber: position.lineNumber,
                        startColumn: word.startColumn,
                        endColumn: word.endColumn
                    };
                    return {
                        suggestions: createDependencyProposals(range, data[oneLanguage])
                    };
                }
            });
        }
        resolve();
    });

}

function createDependencyProposals(range, data) {
    let response = [];
    for (let suggestion of data) {
        response.push({
            label: suggestion[0],
            kind: monaco.languages.CompletionItemKind.Function,
            insertText: suggestion[1],
            range: range
        })
    }
    return response;
}

function getCompletionConfig() {
    return {
        javascript: [
            ["gitee.getFileContent 获取文件内容", "gitee.getFileContent(filePath, refresh = false, parseJson = false, repo = pubRepo)"],
            ["gitee.updateFile 更新文件内容", "gitee.updateFile(filePath, content, repo = pubRepo)"],
            ["gitee.getFileTree 获取文件树", "gitee.getFileTree(refresh = false, repo = pubRepo)"],
            ["gitee.newFile 创建文件", "gitee.newFile(filePath, content, repo = pubRepo)"],
            ["utils.message 提示框", "utils.message(msg, type = 'success')"],
            ["utils.messageBox 弹出框", "utils.messageBox(msg, type = 'alert')"],
            ["utils.notify 消息框", "utils.notify(msg, type = 'success')"]
        ],
        markdown: [
        ]
    }
}